package graphs;



import odor.Odor;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;


/**
 * Produces a simple Input v.s Ouput graph based on Odor data, Odors as a series
 * @author pedro
 *
 */
public class XYOdorInputVOutputJGraph extends XYInputsVOuputGraph 
{

	public XYOdorInputVOutputJGraph(Odor input, double[] outputs)
	{
		dataSet = new XYSeriesCollection();
		XYSeries data = new XYSeries(input.toString());
		
		double[] inputs = input.getInputs();
		
		for (int x=0; x<outputs.length; x++)
		{
			data.add(inputs[x], outputs[x]);
		}
		
		dataSet.addSeries(data);
		
		super.makeChart();
	}
	
	public void addXYSeries(Odor input, double[] outputs)
	{
		XYSeries data = new XYSeries(input.toString());
		double[] inputs = input.getInputs();
		
		for (int x=0; x<outputs.length; x++)
		{
			data.add(inputs[x], outputs[x]);
		}
		
		if (this.contains(input) == false)
		{	
			this.dataSet.addSeries(data);
		}
	}
	
	public boolean contains(Odor input)
	{
		if (this.dataSet.getSeries() == null || input == null)
		{
			return false;
		}
		
		for(int x=0; x<this.dataSet.getSeriesCount(); x++)
		{
			XYSeries serie = this.dataSet.getSeries(x);

			if (((String)serie.getKey()).compareTo(input.toString()) == 0)
			{
				return true;
			}
		}
		
		return false;
		
	}
}
